﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CookieLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BtnLogin_Click(object sender, EventArgs e)
    {
        if (TbUsername.Text == "admin" && TbPassword.Text == "123")
        {
            HttpCookie cookie = new HttpCookie("username");
            // 设置Cookie的值
            cookie.Value = "admin";
            //设置Cookie过期的时间值
            cookie.Expires = DateTime.Now.AddHours(1);
            //把cookie添加进去
            Response.Cookies.Add(cookie);
        }
    }
}